while True:
    # 定义用户名的合法字符数
    hefazifu = 0
    # 判断用户名是否合法
    username = input("请输入用户名：")
    if len(username) <= 8 and len(username) > 0:
        
        for u in username:
            if  u.isalnum() or u=="_":
                hefazifu = hefazifu + 1
            else:
                print("只能由数字、字母、下划线组成")
                break
        if len(username) == hefazifu:
            print(username)
            print("用户名合法！")
    else:
        print("ID长度不能超过8位.也不能为空！")
        break
    
    # 判断邮箱是否合法     
    email = input("请输入email：")
    if email.find('@') == -1:
        print("请输入正确的邮箱地址：")
        break
    elif email.find('@') == 0:
        print("邮箱第一个字符不能为@：")
        break
    elif email.find('@') ==len(email)-1:
        print('@不能结尾，请输入正确邮箱')
        break
    elif email[-1:-4] != ".com":
        print("需要以.com结尾！")
        break
    else:
        print(email)

    # 判断身份证是否合法
    ID = input('请输入十八位身份证号码: ')

    if len(ID) == 18:
        print("你的身份证号码是 " + ID)
    else:
        print("错误的身份证号码")

    ID_add = ID[0:6]
    ID_birth = ID[6:14]
    ID_sex = ID[14:17]
    ID_check = ID[17]

    year = ID_birth[0:4]
    moon = ID_birth[4:6]
    day = ID_birth[6:8]

    print("生日: " + year + '年' + moon + '月' + day + '日')

    if int(ID_sex) % 2 == 0:
        print('性别：女')
    else:
        print('性别：男')
    
    W = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
    ID_num = [18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2]
    ID_CHECK = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']
    ID_aXw = 0
    
    for i in range(len(W)):
        ID_aXw = ID_aXw + int(ID[i]) * W[i]
    ID_Check = ID_aXw % 11
    if ID_check == ID_CHECK[ID_Check]:
        print('正确的身份证号码')
    else:
        print('错误的身份证号码')


    # 输入姓名    
    name = input("请输入姓名：")
    print(name)
    break
